package com.dcy.daily.skill.rabbitMQ.springAMQP.tmp.batch;

import com.dcy.daily.common.config.annotation.ComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.BatchingRabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;

import java.nio.charset.StandardCharsets;

/**
 * batchingRabbitTemplate批量发送
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年07月22日 11:12
 */
@ComponentUtil.UComponent
public class Send implements ApplicationRunner {

    public static final Logger logger = LoggerFactory.getLogger(Send.class);

    @Autowired
    private BatchingRabbitTemplate batchingRabbitTemplate;

    /**
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        String msg;
        Message message;
        MessageProperties messageProperties=new MessageProperties();
        for (int i = 0; i < 10000; i++) {
            msg="batch."+i;
            message = new Message(msg.getBytes(StandardCharsets.UTF_8),messageProperties);
            batchingRabbitTemplate.send("myqueue",message);
        }
    }
}
